package com.bjpowernode.boss.mvc.models.response;

import com.bjpowernode.boss.enums.RespInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AjaxResult {

    private Integer code;

    private String msg;

    private Object data;

    public static AjaxResult OK() {
        return AjaxResult
                .builder()
                .code(RespInfo.SUCCESS.getCode())
                .msg(RespInfo.SUCCESS.getMessage())
                .build();
    }

    public static AjaxResult OK(Object data) {
        return AjaxResult
                .builder()
                .code(RespInfo.SUCCESS.getCode())
                .msg(RespInfo.SUCCESS.getMessage())
                .data(data)
                .build();
    }

    public static AjaxResult FAIL(RespInfo respInfo) {
        return AjaxResult
                .builder()
                .code(respInfo.getCode())
                .msg(respInfo.getMessage())
                .build();
    }


    public static AjaxResult FAIL(Object data) {
        return AjaxResult.builder().code(901).msg("失败").build();
    }

}
